package first.endtoend.tsm

import org.mbds.wolf.tsm.gp.systems.messaging2_1_0.ksoap2.services.types.Enums
import org.mbds.wolf.tsm.gp.systems.messaging2_1_0.ksoap2.services.types.ExecutionStatusType
import org.mbds.wolf.tsm.gp.systems.messaging2_1_0.ksoap2.services.types.StatusCodeDataType
import org.mbds.wolf.tsm.gp.systems.messaging2_1_0.ksoap2.services.types.requests.data.CheckGlobalEligibilityResponseDataType
import org.mbds.wolf.tsm.gp.systems.messaging2_1_0.ksoap2.services.types.requests.responses.CheckGlobalEligibilityResponseType


class CheckGlobalEligibilityResponseService
{

    final CheckGlobalEligibilityResponseType responseType


    CheckGlobalEligibilityResponseService(CheckGlobalEligibilityResponseType responseType)
    {
        this.responseType = responseType
    }

    /**
     * Format a CheckGlobalEligibilityResponseType in a HashMap
     * @return
     */
    HashMap<String, String> format()
    {
        HashMap<String, String> display = new HashMap<>()
        String str = ""
        Date startDate = responseType.ProcessingStart;
        Date endDate = responseType.ProcessingEnd;
        BigInteger validityPeriod = responseType.AcceptableValidityPeriod;
        ExecutionStatusType executionStatus = responseType.FunctionExecutionStatus;
        Enums.StatusType status = executionStatus.Status;
        StatusCodeDataType data = executionStatus.StatusCodeData;
        String subject = data.Subject;
        String reason = data.Reason;
        String message = data.Message;
        String subjectIdentifier = data.SubjectIdentifier;
        CheckGlobalEligibilityResponseDataType responseData = responseType.ResponseData;
        Boolean isEligible = responseData.Eligible;
        ArrayList<BigInteger> reasons = null;
        if (!isEligible)
        {
            reasons = responseData.NonEligibilityReason;
            for (BigInteger b : reasons)
            {
                str += b.toString() + ", ";
            }
        }
        display.put("Start Date", startDate.toString());
        display.put("End Date", endDate.toString());
        display.put("Validity Period", validityPeriod.toString());
        display.put("Status", status.toString());
        display.put("Subject", subject.toString());
        display.put("Reason", reason.toString());
        display.put("Message", message.toString());
        display.put("Subject Identifier", subjectIdentifier.toString());

        display.put("Reasons", str);

        return display
    }
}
